home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / xfcn / spttool.cpt / Support Tools eXternals 1.2.5 / card_33847.txt < prev    next >
Encoding:
Text File  |  1990-11-14  |  11.2 KB  |  307 lines

  1. -- card: 33847 from stack: in.5
  2. -- bmap block id: 9273
  3. -- flags: 0000
  4. -- background id: 3858
  5. -- name: FileModDate
  6. ----- HyperTalk script -----
  7. on HideObjects
  8.   hide cd btn "Try It!"
  9. end HideObjects
  10.  
  11. on ShowObjects
  12.   show cd btn "Try It!"
  13. end ShowObjects
  14.  
  15.  
  16. -- part 1 (button)
  17. -- low flags: 00
  18. -- high flags: A002
  19. -- rect: left=82 top=185 right=219 bottom=175
  20. -- title width / last selected line: 0
  21. -- icon id / first selected line: 0 / 0
  22. -- text alignment: 1
  23. -- font id: 0
  24. -- text size: 12
  25. -- style flags: 8192
  26. -- line height: 16
  27. -- part name: Try it!
  28. ----- HyperTalk script -----
  29. on mouseUp
  30.   global errGlobal
  31.   put FilePath("", "Choose a file please.") into fileName
  32.   if fileName = empty then exit mouseUp
  33.   put FileModDate(fileName, "nodialog:errGlobal") into fDate
  34.   if errGlobal Γëá empty then
  35.     answer "Error: ΓÇ£" & errGlobal & "ΓÇ¥"
  36.     put empty into errGlobal
  37.   else
  38.     convert fDate to short date
  39.     answer "ΓÇ£" & fileName & "ΓÇ¥ was last modified on" && fDate
  40.   end if
  41. end mouseUp
  42.  
  43.  
  44.  
  45.  
  46. -- part contents for background part 38
  47. ----- text -----
  48. 17/50
  49.  
  50. -- part contents for background part 20
  51. ----- text -----
  52. FileModDate - An XFCN to return the modification date of a file or folder.
  53.  
  54. FileModDate(pathname,«"noDialog:"errorGlobal»)
  55.  
  56. This XFCN returns the time and date the specified file OR folder (despite the name) was last modified.  Like its sibling, FileCreationDate, FileModDate returns this value in the form of seconds since 1904.  Pass this value to HyperCard's convert function to change it to a more legible format.
  57.  
  58.  
  59. -- part contents for background part 42
  60. ----- text -----
  61. { FileModDate(pathname ┬½,"nodialog":errGlobal┬╗)       }
  62. {}
  63. { XFCN to return the creator for the file specified by      }
  64. { the path given in the first parameter.                        }
  65. {}
  66. {}
  67. {   Written by:      Anup Murarka         Eric Carlson                                             }
  68. {               ALINK:  SKEPTIC       ALINK:  cyNic                                               }
  69. {                                   CIS:  76004,3356}
  70. {}
  71. {               We are part of the Support Tools Development Group,                     }
  72. {               Apple Computer, Inc.                                                                      }
  73. {}
  74. {               PLEASE DO NOT CONTACT Mac DTS for support of this code!           }
  75. {}
  76. {               PLEASE DO CONTACT the authors for support of this code!            }
  77. {}
  78. {               Send comments, bug reports, requests to any of the above           }
  79. {               E-mail addresses or to:                                                                  }
  80. {}
  81. {                           (one of us)                              }
  82. {                           Apple Computer, Inc.                  }
  83. {                           900 E. Hamilton, Ave.              }
  84. {                           Campbell, CA   95008              }
  85. {                           M/S 72-L                                 }
  86. {}
  87. {   Copyright:   ┬⌐ 1989, 1990 by Apple Computer, Inc., all rights reserved.}
  88. {}
  89. { written by    : Anup Murarka                                                                           }
  90. { AppleLink  : Skeptic                                                                                  }
  91. { modification history                                                                                    }
  92. {          Date              Initials                                    Comments                                   }
  93. {          ----          ------          --------------------------------------------------     }
  94. {       8/16/89           akm         first written                                                                   }
  95. {       5/4/90             ec            modified for A/UX compatibility, removed upper case     }
  96. {                                           conversion.  Changed version to 1.1                                     }
  97. {}
  98. unit FileModDate;
  99.  
  100. interface
  101.  
  102.     uses
  103.         HyperXCmd;
  104.  
  105.     procedure MAIN (paramPtr: XCmdPtr);
  106.  
  107. implementation
  108.  
  109.     procedure FileModDate (paramPtr: XCmdPtr);
  110.     FORWARD;
  111.  
  112.     procedure MAIN (paramPtr: XCmdPtr);
  113.     begin
  114.         FileModDate(paramPtr);
  115.     end;
  116.  
  117.     procedure reportToUser (paramPtr: XCmdPtr; msgStr: str255);
  118. {}
  119. { report something back to the user.  }
  120. { the last parameter (optional) to an external may contain }
  121.  { "noDialog" or "noDialog:GlobalName".  GlobalName is the name }
  122.  { of a HyperTalk global variable into which error messages will be }
  123.  { placed.  we've decided to use this approach to avoid confusing }
  124. { an error message with a valid result being returned from an XFCN. }
  125. {}
  126.         var
  127.             tempStr: str255;
  128.     begin
  129. {check the last param to see if the user requested that}
  130. { we suppress the error dialog }
  131.         ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr);
  132.         UprString(tempStr, true);
  133.         if pos('NODIALOG', tempStr) = 0 then
  134.     { no special error handling specified, throw up a dialog and return the error message }
  135.             begin
  136.                 SendCardMessage(paramPtr, concat('answer "', msgStr, '"'));
  137.                 paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  138.             end
  139.         else if (pos(':', tempStr) > 0) then
  140.     { requested global AND noDialog so we fill in the global and return empty }
  141.             begin
  142.                 tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr));
  143.                                                         { get the name of the HC global  to fill }
  144.                 SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr));
  145.                                                         { and fill it }
  146.                 paramPtr^.returnValue := PasToZero(paramPtr, '');      { return empty }
  147.             end
  148.         else
  149.     { requested noDialog only so we return the error condition as the result }
  150.             paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  151.     end;     { procedure }
  152.  
  153.     function AskedForHelp (paramPtr: XCmdPtr; syntaxMsg: Str255; copyrightMsg: Str255): boolean;
  154. {   check to see if the user sent a '?' or a '!' as }
  155. { the only parameter. if so we will respond with }
  156. { the calling syntax or the copyright/version info }
  157. { for this external }
  158. {}
  159.         var
  160.             firstStr: str255;
  161.     begin
  162.         askedForHelp := false;
  163.         if paramPtr^.paramCount = 1 then
  164.             begin
  165.                 ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
  166.                     { what is the first param? }
  167.                 if firstStr = '?' then
  168.                     begin
  169.                         reportToUser(paramPtr, syntaxMsg);
  170.                         askedForHelp := true
  171.                     end  { asked for help }
  172.                 else if firstStr = '!' then
  173.                     begin
  174.                         reportToUser(paramPtr, copyRightMsg);
  175.                         askedForHelp := true
  176.                     end;     { asked for copyright info }
  177.             end;     { one parameter passed }
  178.     end;     { function }
  179.  
  180.     function LongToString (paramPtr: XCmdPtr; num: LONGINT): Str255;
  181. { why, oh why did dan write this one as a procedure??? }
  182.         var
  183.             tempStr: str255;
  184.     begin
  185.         LongToStr(paramPtr, num, tempStr);
  186.         LongToString := tempStr;
  187.     end;
  188.  
  189.     function NumberToString (paramPtr: XCmdPtr; num: LONGINT): Str255;
  190. { use the toolbox call rather than HC's }
  191.         var
  192.             tempStr: str255;
  193.     begin
  194.         NumToString(num, tempStr);
  195.         NumberToString := tempStr;
  196.     end;
  197.  
  198.     procedure reportResError (paramPtr: XCmdPtr; errorNum: integer);
  199.         var
  200.             errMsg, tempName: str255;
  201.     begin
  202.         case errorNum of                   { what caused the problem? }
  203.             -0: 
  204.                 errMsg := 'no error.';
  205.             -36: 
  206.                 errMsg := 'I/O Error.';
  207.             -37: 
  208.                 errMsg := 'bad file name or volume name.';
  209.             -38: 
  210.                 errMsg := 'file not open.';
  211.             -39: 
  212.                 errMsg := 'that file has no resource fork.';
  213.             -42: 
  214.                 errMsg := 'too many files open.';
  215.             -43: 
  216.                 errMsg := 'file not found.';
  217.             -45, -54, -61: 
  218.                 errMsg := 'file locked.';
  219.             -47, -49: 
  220.                 errMsg := 'file is busy.';
  221.             -53: 
  222.                 errMsg := 'that volume is not on line.';
  223.             -108: 
  224.                 errMsg := 'not enough room in heap zone.';
  225.             -120: 
  226.                 errMsg := 'directory not found.';
  227.             -121: 
  228.                 errMsg := 'too many working directories open.';
  229.             -127: 
  230.                 errMsg := 'internal file system error.';
  231.             -192: 
  232.                 errMsg := 'resource not found.';
  233.             -193: 
  234.                 errMsg := 'file not found.';
  235.             otherwise
  236.                 errMsg := concat('unexpected error #', NumberToString(paramPtr, errorNum));
  237.         end;         { case }
  238.  
  239.         errMsg := concat('Sorry, ', errMsg);
  240.         reportToUser(paramPtr, errMsg);
  241.         { return the error message }
  242.     end;         { function }
  243.  
  244.     function getParams (paramPtr: XCmdPtr; var PathToFile: str255): boolean;
  245.     { function to get the parameters and validate them.  Returns boolean}
  246.     { instructing the main procedure to continue if the parameters passed}
  247.     { are valid.  Also returns syntax messages if requested by the user.}
  248.         var
  249.             numParams: integer;
  250.             syntaxStr, copyrightStr: str255;
  251.  
  252.     begin
  253.         getParams := true;     {Initially, assume the parameters are valid.}
  254.         syntaxStr := 'FileModDate(pathname ┬½, ΓÇ£nodialogΓÇ¥:errGlobal)';
  255.         copyrightStr := '┬⌐ 1989,1990 Apple Computer, Inc., v.1.1, by Anup Murarka';
  256.  
  257.         {check that we have the proper number of parameters}
  258.         numParams := paramPtr^.paramCount;
  259.         if (numParams < 1) or (numParams > 2) then
  260.             begin
  261.                 getParams := false;
  262.                 reportToUser(paramPtr, syntaxStr);
  263.                 exit(getParams);
  264.             end;
  265.  
  266.         if AskedForHelp(paramPtr, syntaxStr, copyrightStr) then
  267.             begin
  268.                 getParams := false;
  269.                 exit(getParams);
  270.             end;
  271.  
  272.         { Get first parameter}
  273.         ZeroToPas(paramPtr, paramPtr^.Params[1]^, PathToFile);
  274.     end;     {GetParams}
  275.  
  276.     procedure FileModDate (paramPtr: XCmdPtr);
  277.         var
  278.             getParamsOK: boolean;
  279.             charIndex: integer;
  280.             FileName: str255;
  281.             paramBlock: CInfoPBRec;
  282.             errorCode: OSerr;
  283.  
  284.     begin   { FileModDate}
  285.     { fetch and validate the passed parameters}
  286.         getParamsOK := getParams(paramPtr, FileName);
  287.         if not (getParamsOK) then
  288.             exit(FileModDate);
  289.  
  290.     { Initialize the parameter block.  Since we have the full pathname,}
  291.     { no other field is really needed.}
  292.         zeroBytes(paramPtr, @paramBlock, sizeOf(paramBlock));
  293.         paramBlock.ioNamePtr := @FileName;
  294.  
  295.         errorCode := PBGetCatInfo(@paramBlock, FALSE);
  296.         if errorCode <> noErr then
  297.             begin
  298.                 reportResError(paramPtr, errorCode);
  299.                 exit(FileModDate)
  300.             end;
  301.  
  302.     { Now prepare the return value.  Use FileName as a temp variable}
  303.         FileName := LongToString(paramPtr, paramBlock.ioFlMdDat);
  304.         paramPtr^.returnValue := PasToZero(paramPtr, FileName);
  305.     end;
  306.  
  307. end.